package com.aaa.mrcai.service.impl;

import com.aaa.mrcai.mapper.UserOrderMapper;
import com.aaa.mrcai.pojo.entity.AdminOrder;
import com.aaa.mrcai.pojo.entity.UserInfo;
import com.aaa.mrcai.query.UserOrderQuery;
import com.aaa.mrcai.result.AjaxResult;
import com.aaa.mrcai.service.UserOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import javax.servlet.ServletContext;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:Li-Yan-Chun
 * @Date:2021/12/20 19:35
 */
@Service
public class UserOrderServiceImpl implements UserOrderService {
    @Autowired
    private UserOrderMapper userOrderMapper;

    @Autowired
    private ServletContext servletContext;

    @Override
    public AjaxResult list(UserOrderQuery userOrderQuery) {
        UserInfo user = (UserInfo) servletContext.getAttribute("user");
        Integer uid = user.getUserLogin().getUid();
        userOrderQuery.setUid(uid);
        Map<String, Object> map = new HashMap<>();
        List<AdminOrder> list = userOrderMapper.list(userOrderQuery);
        Long aLong = userOrderMapper.queryTotal(userOrderQuery);
        map.put("currentData",list);
        map.put("currentDataTotal",aLong);
        return AjaxResult.success(map);
    }
}
